local tenyear_1v2_c = [[
  # 兵临城下模式简介
    搬运自huosan服 祈 大佬
  ___
游戏由三人进行，一人扮演城主（主公），其他两人扮演联军（反贼），使用官方卡组和强化卡组，移除【乐不思蜀】，请开启神武卡牌/神武衍生牌/兵临城下拓展牌卡组。

  推荐选择  十周年/移动版(手杀)/OL/国际服/雀魂-神武：协力/雀魂-神武：强攻以及对应的衍生牌卡包  拓展包武将进行游戏，使用玩家自身的天牢选将

  额外卡牌：水淹七军，兵临城下，投石车，落井下石，白衣渡江；卡牌详情请至兵临城下拓展牌查看

  城主选将框+2，增加一点体力上限和体力，初始手牌+1，选择武将前，公布本局城池，地主选将后获得对应效果/技能：

  - **樊城**："限定技，出牌阶段，你选择令本局游戏【杀】或非【杀】对其他角色造成的伤害+1"。

  - **襄阳**："结束阶段摸一张牌，然后选择获得一个额外的：1.出牌阶段；2.摸牌阶段"。

  - **江陵**："出牌阶段开始时，你可以令本回合使用牌：1.没有次数限制和距离限制；2.可选择的目标+1，额外目标不可响应此牌"。

  - **虎牢**："锁定技，你视为拥有“无双”/“马术”，你不能成为延迟锦囊的目标，摸牌阶段的摸牌数+"1。

  - **徐州**："你的初始手牌和手牌上限+3，结束阶段，你可以重铸两张牌"。

  - **合肥**："摸牌阶段，你可以少摸任意张牌，改为获得等量其他角色各一张牌；出牌阶段可用【杀】的次数+1"。

  - **颍川**："锁定技，你视为拥有“慧识”；当你受到伤害时，该伤害额外增加你发动“慧识”的次数"。

  - **洛阳**："锁定技，准备，你可以选择一名角色，弃置一张牌，对其造成随机0-2点火焰伤害"

  - **宛城**："限定技，第二轮后的出牌阶段，你可以选择一项：回复体力至上限，摸三张牌令一名联军获得“雄乱”；获得“雄乱”，令一名联军回复体力至上限并摸三张牌"。

  - **陈仓**："结束阶段，你可以依次弃置场上至多6-X张牌(X为你的手牌数)"。

  - **荆州**："出牌阶段限一次，你可以将所有手牌当做一张不可响应的【白衣渡江】使用并回复一点体力；你不能成为其他角色【白衣渡江】的目标"。

  - **永安**："获得“疫病”。锁定技，摸牌阶段，你少摸一张牌并失去一点体力；当你失去体力后，你随机获得牌堆中的两张牌，并令一名角色获得此技能，其不受摸牌减少和失去体力获得牌的效果影响"。

  - **葭萌**："准备阶段开始时，你可以选择一名联军，令其有15％的概率倒戈为忠臣，若倒戈失败，你失去一点体力摸一张牌，视为对其使用一张杀，每次失败会增加5％的成功率"。

  - **雏城**："锁定技，当你使用【杀】造成伤害时，此伤害额外增加X(X为本局游戏所有角色的回复量总和)"。

  - **流放之地**：你视为拥有 “飞扬/跋扈”。

  地主额外获得技能：

  - **粮绝**："锁定技，游戏轮次大于4后，摸牌阶段，你少摸一张牌"。

  联军在游戏开始时获得技能效果：

  - **歃血**：锁定技，每局游戏限三次，当你受到来自联军的伤害时(包含自己)，防止之。

  - **兵尽**："锁定技，游戏轮次大于3后，结束阶段，你失去一点体力，游戏伦次为9时，结束阶段，你死亡"。

  当联军死亡时，另一名联军可以选择：摸两张牌，或者回复一点体力。

  *击杀联军的人没有摸三张牌的奖励。*

  胜利规则：

  - **城主**：击杀所有联军或于第四轮起击杀一名联军。

  - **联军**：击杀城主。

]]

-- Because packages are loaded before gamelogic.lua loaded
-- so we can not directly create subclass of gamelogic in the top of lua
local U = require "packages/utility/utility"
local m_1v2_getLogic = function()
  local m_1v2_logic = GameLogic:subclass("m_1v2_logic")

  function m_1v2_logic:initialize(room)
    GameLogic.initialize(self, room)
    self.role_table = { nil, nil, { "lord", "rebel", "rebel" } }
  end

  function m_1v2_logic:prepareDrawPile()
    local room = self.room
    room.black_cardNames = { "indulgence", "sw_xsnh", "sw_swfjj", "sw_sfj", "sw_hlzjg", "nz_nvzhuang",
      "yfj_yinfengjia", "jh_jinhe", "sw_yhshl", "sw_qxdgq", "sw_wsxlj", "sw_mao", "s_niepan", "huoshangjiaoyou",
      "sw_llsmd" }
    local allCardIds = Fk:getAllCardIds()
    --重新过滤卡组
    local filterCardIds = {}
    local while_cards = { "standard", "standard_cards", "tenyear1v2_cards", "maneuvering", "MahjongSoul_token",
      "MahjongSoul_tokenT", "tenyear_token", "mobile_derived", "ol_token", "overseas_token" }
    local black_cardNames = room.black_cardNames
    for i = #allCardIds, 1, -1 do
      local id = allCardIds[i]
      local card = Fk:getCardById(id)
      if card then
        if card.is_derived or (not table.contains(while_cards, card.package.name)) or table.contains(black_cardNames, card.name) then
          table.removeOne(allCardIds, id)
          table.insert(room.void, id)
          room:setCardArea(id, Card.Void, nil)
        end
      end
      if table.contains(while_cards, card.package.name) and not table.contains(black_cardNames, card.name) then
        if not card.is_derived then
          table.insert(filterCardIds, id)
        end
      end
    end
    table.shuffle(filterCardIds)
    room.draw_pile = filterCardIds
    for _, id in ipairs(room.draw_pile) do
      room:setCardArea(id, Card.DrawPile, nil)
    end
  end

  function m_1v2_logic:chooseGenerals()
    local room = self.room ---@type Room
    local generalNum = room.settings.generalNum
    local chengzhuskill = { "sw_xiangyang&", "sw_fancheng&", "sw_jiangling&", "sw_hulao&", "sw_xuzhou&", "sw_hefei&",
      "sw_yingchuan&", "sw_wancheng&", "sw_putong&", "sw_chencang&", "sw_jingzhou&", "sw_luoyang&", "sw_xiameng&",
      "sw_yongan&","sw_chucheng&" }
    local skills = table.random(chengzhuskill, 1)[1]
    if skills == "sw_putong&" then
      for i = 1, 3, 1 do
        room:doBroadcastNotify("ShowToast", "<font color='red'>本局城池为：流放之地，点击左上角查看城主技能，若不熟悉模式，请前往玩法一览→模式简介查看模式规则!</font>")
      end
    else
      for i = 1, 3, 1 do
        room:doBroadcastNotify("ShowToast",
          "<font color='red'>本局城池为：" .. Fk:translate(skills) .. "，点击左上角查看城主技能，若不熟悉模式，请前往玩法一览→模式简介查看模式规则!</font>")
      end
    end
    room:setBanner("@[:]skillchengchi", skills)
    for _, p in ipairs(room.players) do
      p.role_shown = true
      room:broadcastProperty(p, "role")
      room:setPlayerMark(p, "chengzhu", skills)
    end

    local lord = room:getLord()
    room.current = lord
    local nonlord = room.players
    -- 地主多发俩武将
    local generals = room:getNGenerals(#nonlord * generalNum + 2)
    for i, p in ipairs(nonlord) do
      local arg = table.slice(generals, (i - 1) * generalNum + 1, i * generalNum + 1)
      if p.role == "lord" then
        local count = #generals
        table.insert(arg, generals[count])
        table.insert(arg, generals[count - 1])
      end
      p.request_data = json.encode({ arg, 1 })
      p.default_reply = arg[1]
    end
    room:notifyMoveFocus(nonlord, "AskForGeneral")
    room:doBroadcastRequest("AskForGeneral", nonlord)
    local selected = {}
    for _, p in ipairs(nonlord) do
      local general_ret
      if p.general == "" and p.reply_ready then
        general_ret = json.decode(p.client_reply)[1]
      else
        general_ret = p.default_reply
      end
      room:setPlayerGeneral(p, general_ret, true, true)
      table.insertIfNeed(selected, general_ret)
      p.default_reply = ""
    end
    generals = table.filter(generals, function(g) return not table.contains(selected, g) end)
    room:returnToGeneralPile(generals)
    room:askForChooseKingdom(nonlord)

    for _, p in ipairs(nonlord) do
      room:broadcastProperty(p, "general")
      if p.role == "lord" then
        room:broadcastProperty(p, "kingdom")
      end
    end
  end

  return m_1v2_logic
end
local sw_hulao = fk.CreateTriggerSkill {
  name = "sw_hulao&",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = { fk.DrawNCards },
  on_use = function(self, event, target, player, data)
    data.n = data.n + 1
  end,
}
local sw_hulao_prohit = fk.CreateProhibitSkill {
  name = "#sw_hulao_prohit",
  is_prohibited = function(self, from, to, card)
    return to:hasSkill("sw_hulao&") and card and card.sub_type == Card.SubtypeDelayedTrick
  end,
}
sw_hulao:addRelatedSkill(sw_hulao_prohit)
Fk:addSkill(sw_hulao)
Fk:loadTranslationTable {
  ["sw_hulao&"] = "虎牢",
  [":sw_hulao&"] = "锁定技，你视为拥有“无双”/“马术”，你不能成为延时类锦囊牌的目标，摸牌阶段的额定摸牌数+1",
}
local sw_wancheng = fk.CreateActiveSkill {
  name = "sw_wancheng&",
  prompt = "#sw_wancheng-active",
  card_num = 0,
  target_num = 0,
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and
        player:usedSkillTimes(self.name, Player.HistoryRound) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    if room:getTag("RoundCount") < 2 then
      player:setSkillUseHistory("sw_wancheng&", 0, Player.HistoryGame)
    else
      local chc = { "sw_wancheng_give", "sw_wancheng_activ" }
      local chs = room:askForChoice(player, chc, self.name)
      if chs == "sw_wancheng_give" then
        room:recover({ who = player, num = player.maxHp - player.hp, recoverBy = player, skillName = self.name })
        player:drawCards(3)
        local to = room:askForChoosePlayers(player, table.map(player.room.alive_players, function(p)
          return p.id ~= player.id and p.id
        end), 1, 1, "#give_xiongluan", self.name, false)
        if #to > 0 then
          room:handleAddLoseSkills(room:getPlayerById(to[1]), "xiongluan", nil, false)
        end
      else
        room:handleAddLoseSkills(player, "xiongluan", nil, false)
        local to = room:askForChoosePlayers(player, table.map(player.room.alive_players, function(p)
          return p.id ~= player.id and p.id
        end), 1, 1, "#chos_huixue", self.name, false)
        if #to > 0 then
          room:recover({
            who = room:getPlayerById(to[1]),
            num = player.maxHp - player.hp,
            recoverBy = player,
            skillName = self.name
          })
          room:getPlayerById(to[1]):drawCards(3)
        end
      end
    end
  end,
}
Fk:addSkill(sw_wancheng)
Fk:loadTranslationTable {
  ["sw_wancheng&"] = "宛城",
  ["sw_wancheng_give"] = "回复体力至上限，摸三张牌，令一名联军获得“雄乱”",
  ["sw_wancheng_activ"] = "获得“雄乱”，令一名联军回复体力至上限并摸三张牌",
  ["#give_xiongluan"] = "宛城：选择一个获得雄乱的联军",
  ["#chos_huixue"] = "宛城：选择一个回复体力摸牌的联军",
  [":sw_wancheng&"] = "限定技，第二轮开始后的出牌阶段，你可以选择一项：获得“雄乱”，令一名联军回复体力至上限，摸三张牌；回复体力至上限，摸三张牌，令一名联军获得“雄乱”；若于第二轮前发动无效果",
}
local sw_jingzhou = fk.CreateViewAsSkill {
  name = "sw_jingzhou&",
  anim_type = "offensive",
  prompt = "#sw_jingzhou-viewas",
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local card = Fk:cloneCard("bydj")
    card:addSubcards(Self:getCardIds(Player.Hand))
    card.skillName = self.name
    return card
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  before_use = function(self, player, use)
    local room = player.room
    room:recover({
      who = player,
      num = 1,
      recoverBy = player,
      skillName = self.name
    })
  end,
}

local sw_jingzhou_tar = fk.CreateTriggerSkill {
  name = "#sw_jingzhou_tar",
  anim_type = "offensive",
  events = { fk.CardUsing },
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill("sw_jingzhou&") and data.card.name == "bydj"
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke("sw_kanpo")
    data.disresponsiveList = data.disresponsiveList or {}
    for _, p in ipairs(player.room.alive_players) do
      table.insertIfNeed(data.disresponsiveList, p.id)
    end
  end,
}
local sw_jingzhou_prohibit = fk.CreateProhibitSkill {
  name = "#sw_jingzhou_prohibit",
  is_prohibited = function(self, from, to, card)
    return to:hasSkill("sw_jingzhou&") and card and card.name == "bydj" and from ~= to
  end,
}
sw_jingzhou:addRelatedSkill(sw_jingzhou_tar)
sw_jingzhou:addRelatedSkill(sw_jingzhou_prohibit)
Fk:addSkill(sw_jingzhou)
Fk:loadTranslationTable {
  ["sw_jingzhou&"] = "荆州",
  ["#sw_jingzhou_tar"] = "荆州",
  ["#sw_jingzhou-viewas"] = "荆州：是否使用一张【白衣渡江】并回复一点体力",
  [":sw_jingzhou&"] = "出牌阶段限一次，你可以将所有手牌当做一张不可响应的【白衣渡江】使用并回复一点体力；你不能成为其他角色【白衣渡江】的目标",
}

local sw_luoyang = fk.CreateTriggerSkill {
  name = "sw_luoyang&",
  anim_type = "drawcard",
  events = { fk.EventPhaseStart },
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(player.room.alive_players, function(p)
      return #p:getCardIds { Player.Hand, Player.Equip, Player.Judge } > 0 and p.id
    end), 1, 1, "#sw_luoyang-askchos", self.name, true)
    if #to > 0 then
      local id = room:askForCardChosen(player, room:getPlayerById(to[1]), "hej", self.name)
      room:throwCard({ id }, self.name, room:getPlayerById(to[1]), player)
      room:damage {
        from = player,
        to = room:getPlayerById(to[1]),
        damage = math.random(0, 2),
        damageType = fk.FireDamage,
        skillName = self.name,
      }
    end
  end
}
Fk:addSkill(sw_luoyang)
Fk:loadTranslationTable {
  ["sw_luoyang&"] = "洛阳",
  ["#sw_luoyang-askchos"] = "洛阳：请选择一名角色，弃置其区域内的一张牌，对其造成随机0-2点火焰伤害",
  [":sw_luoyang&"] = "准备阶段，你可以选择一名其他角色，弃置其区域内的一张牌，对其造成随机0-2点火焰伤害",
}

local sw_xiameng = fk.CreateTriggerSkill {
  name = "sw_xiameng&",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = { fk.EventPhaseStart },
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player.phase == Player.Start and target == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = 0
    local to = room:askForChoosePlayers(player, table.map(player.room.alive_players, function(p)
      return p.role == "rebel" and p.id
    end), 1, 1, "#s", self.name, true)
    if #to > 0 then
      local tar = room:getPlayerById(to[1])
      if math.random() < ((15 + n) / 100) then
        room:setPlayerProperty(tar, "role", "loyalist")
        room:broadcastProperty(tar, "role")
        room:handleAddLoseSkills(tar, "-sw_shameng&", nil, false)
        room:handleAddLoseSkills(tar, "-sw_bingjin&", nil, false)
        room:handleAddLoseSkills(tar, "sw_liangjue&", nil, false)
        local tta = 0
        for _, p in ipairs(room:getOtherPlayers(player)) do
          if p.role == "loyalist" then tta = tta + 1 end
          if tta == (#room.alive_players -1) then
            room:gameOver(player.role)
          end
        end
      else
        n = n + 5
        room:loseHp(player, 1)
        player:drawCards(1)
        local use = {
          from = player.id,
          tos = { { to[1] } },
          card = Fk:cloneCard("slash"),
          extraUse = true,
        }
        use.card.skillName = self.name
        room:useCard(use)
      end
    end
  end,
}
Fk:addSkill(sw_xiameng)
Fk:loadTranslationTable {
  ["sw_xiameng&"] = "葭萌",
  [":sw_xiameng&"] = "准备阶段开始时，你可以选择一名联军，令其有15％的概率倒戈为忠臣，若倒戈失败，你失去一点体力摸一张牌，视为对其使用一张杀，每次失败会增加5％的成功率",
}
local sw_jiangling = fk.CreateTriggerSkill {
  name = "sw_jiangling&",
  anim_type = "control",
  events = { fk.EventPhaseChanging },
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
        data.to == Player.Play
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choices = { "jiangling_wucishu", "jiangling_ewaimubiao" }
    local choice = room:askForChoice(player, choices, self.name, "#sw_jiangling-chos", false,
      { "jiangling_wucishu", "jiangling_ewaimubiao" })
    self.cost_data = choice
    return true
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, self.cost_data .. "-turn", 1)
  end
}
local sw_jiangling_cishu = fk.CreateTargetModSkill {
  name = "#sw_jiangling_cishu",
  frequency = Skill.Compulsory,
  bypass_times = function(self, player, skill, scope, card, to)
    return player:hasSkill("sw_jiangling&") and scope == Player.HistoryPhase and
        player:getMark("jiangling_wucishu-turn") > 0
  end,
  bypass_distances = function(self, player, skill, card)
    return player:hasSkill("sw_jiangling&") and player:getMark("jiangling_wucishu-turn") > 0
  end,
}
local sw_jiangling_ewai = fk.CreateTriggerSkill {
  name = "#sw_jiangling_ewai",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = { fk.CardUsing },
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardUsing and target == player and player:hasSkill("sw_jiangling&") and player:getMark("jiangling_ewaimubiao-turn") > 0 then
      return (data.card.type == Card.TypeBasic or
        data.card:isCommonTrick()) and data.tos and #data.tos == 1
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = U.getUseExtraTargets(room, data)
    if #targets == 0 then return false end
    local tos = room:askForChoosePlayers(player, targets, 1, 1,
      "#sw_jiangling_ewai-choose", self.name, true)
    if #tos > 0 then
      table.forEach(tos, function(id)
        table.insert(data.tos, { id })
      end)
      data.disresponsiveList = data.disresponsiveList or tos
    end
  end,
}
sw_jiangling:addRelatedSkill(sw_jiangling_ewai)
sw_jiangling:addRelatedSkill(sw_jiangling_cishu)
Fk:addSkill(sw_jiangling)
Fk:loadTranslationTable {
  ["@[:]skillchengchi"] = "本局城池",
  ["sw_jiangling&"] = "江陵",
  ["#sw_jiangling_ewai"] = "江陵",
  ["#sw_jiangling-chos"] = "江陵：你可以选择一项：1.使用牌无次数和距离限制；2.使用牌可选择的目标+1，额外目标不可响应此牌",
  [":sw_jiangling&"] = "出牌阶段开始时，你可以选择一项：1.使用牌无次数和距离限制；2.使用仅指定一个目标的基本牌和普通锦囊牌可以选择一个额外目标且额外目标不能响应此牌",
  ["jiangling_wucishu"] = "使用牌无次数和距离限制",
  ["jiangling_ewaimubiao"] = "使用牌可选目标+1且额外目标不能响应此牌",
  ["#sw_jiangling_ewai-choose"] = "江陵：选择一个额外目标吗，该目标无法响应此牌",
}
local sw_fancheng = fk.CreateActiveSkill {
  name = "sw_fancheng&",
  prompt = "#sw_fancheng-active",
  card_num = 0,
  target_num = 0,
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local chc = { "fancheng_noslash", "fancheng_card" }
    local chs = room:askForChoice(player, chc, self.name)
    if chs == "fancheng_noslash" then
      room:setPlayerMark(player, "fancheng_noslash", 1)
    else
      room:setPlayerMark(player, "fancheng_card", 1)
    end
  end,
}
local sw_fancheng_ns = fk.CreateTriggerSkill {
  name = "#sw_fancheng_ns",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = { fk.DamageCaused },
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill("sw_fancheng&") and player:getMark("fancheng_noslash") > 0 and player == target then
      return (data.card and data.card.trueName ~= "slash") or not data.card
    end
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end
}
local sw_fancheng_cs = fk.CreateTriggerSkill {
  name = "#sw_fancheng_cs",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = { fk.AfterCardUseDeclared },
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill("sw_fancheng&") and player:getMark("fancheng_card") > 0 and data.card.trueName == "slash" and
        player == target
  end,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, "sw_fancheng&", "defensive")
    data.additionalDamage = (data.additionalDamage or 0) + 1
  end
}
sw_fancheng:addRelatedSkill(sw_fancheng_cs)
sw_fancheng:addRelatedSkill(sw_fancheng_ns)
Fk:addSkill(sw_fancheng)
Fk:loadTranslationTable {
  ["sw_fancheng&"] = "樊城",
  ["#sw_fancheng_ns"] = "樊城",
  ["#sw_fancheng_cs"] = "樊城",
  ["#sw_fancheng-active"] = "樊城：是否选择令【杀】或非【杀】伤害永久+1",
  ["fancheng_noslash"] = "非【杀】伤害+1",
  ["fancheng_card"] = "【杀】伤害+1",
  [":sw_fancheng&"] = "限定技，出牌阶段，你可以令本局游戏你使用【杀】或非【杀】造成的伤害+1",
}
local sw_yingchuan = fk.CreateTriggerSkill {
  name = "sw_yingchuan&",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = { fk.DamageInflicted },
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
        player:usedSkillTimes("mobile__god_huishi", Player.HistoryGame) > 0
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + player:usedSkillTimes("mobile__god_huishi", Player.HistoryGame)
  end,
}
Fk:addSkill(sw_yingchuan)
Fk:loadTranslationTable {
  ["sw_yingchuan&"] = "颍川",
  [":sw_yingchuan&"] = "锁定技，你视为拥有“慧识”；当你受到伤害时，此伤害额外增加你发动“慧识”的次数",
}
local sw_hefei = fk.CreateTriggerSkill {
  name = "sw_hefei&",
  anim_type = "control",
  events = { fk.DrawNCards },
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.n > 0 and
        not table.every(player.room:getOtherPlayers(player), function(p) return p:isKongcheng() end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room:getOtherPlayers(player), function(p)
      return not p:isKongcheng()
    end), function(p) return p.id end)
    local tos = room:askForChoosePlayers(player, targets, 1, data.n, "#sw_hefei-choose:::" .. data.n, self.name, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, id in ipairs(self.cost_data) do
      local c = room:askForCardChosen(player, room:getPlayerById(id), "h", self.name)
      room:obtainCard(player, c, false, fk.ReasonPrey)
    end
    data.n = data.n - #self.cost_data
  end,
}
local sw_hefei_attack = fk.CreateTargetModSkill { --额外一张杀
  name = "#sw_hefei_attack",
  residue_func = function(self, player, skill, scope, card)
    if card and player:hasSkill("sw_hefei&") and card.trueName == "slash" and scope == Player.HistoryPhase then
      return 2
    end
  end
}
sw_hefei:addRelatedSkill(sw_hefei_attack)
Fk:addSkill(sw_hefei)
Fk:loadTranslationTable {
  ["sw_hefei&"] = "合肥",
  [":sw_hefei&"] = "摸牌阶段，你可以少摸任意张牌并获得等量其他角色各一张手牌；出牌阶段可用【杀】的次数+1",
  ["#sw_hefei-choose"] = "合肥：你可以少摸至多 %arg 张牌，获得等量其他角色各一张手牌",
}

local sw_xiangyang = fk.CreateTriggerSkill {
  name = "sw_xiangyang&",
  anim_type = "control",
  events = { fk.EventPhaseChanging },
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
        data.to == Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choices = { "sw_xiangyang_play", "sw_xiangyang_draw" }
    local choice = room:askForChoice(player, choices, self.name, "#sw_xiangyang_chos", false,
      { "sw_xiangyang_play", "sw_xiangyang_draw" })
    self.cost_data = choice
    return true
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1)
    if self.cost_data == "sw_xiangyang_play" then
      player:gainAnExtraPhase(Player.Play)
    else
      player:gainAnExtraPhase(Player.Draw)
    end
  end
}
Fk:addSkill(sw_xiangyang)
Fk:loadTranslationTable {
  ["sw_xiangyang&"] = "襄阳",
  ["sw_xiangyang_play"] = "出牌阶段",
  ["sw_xiangyang_draw"] = "摸牌阶段",
  ["#sw_xiangyang_chos"] = "襄阳：是否选择执行一个额外的摸牌阶段或出牌阶段",
  [":sw_xiangyang&"] = "结束阶段摸一张牌，你可以选择执行一个额外的摸牌阶段或出牌阶段",
}
local sw_chencang = fk.CreateTriggerSkill {
  name = "sw_chencang&",
  anim_type = "control",
  events = { fk.EventPhaseEnd },
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player == target and player.phase == Player.Finish and
        #player:getCardIds(player.Hand) < 6
  end,
  on_cost = function(self, event, target, player, data)
    local n = 6 - player:getHandcardNum()
    return player.room:askForSkillInvoke(player, self.name, nil, "#sw_chencang-ask:::" .. n)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = 6 - player:getHandcardNum()
    for i = 1, n, 1 do
      local to = room:askForChoosePlayers(player, table.map(player.room.alive_players, function(p)
        return #p:getCardIds { Player.Hand, Player.Equip, Player.Judge } > 0 and p.id
      end), 1, 1, "#sw_nianshou-1:::" .. i .. ":" .. n, self.name, true)
      if #to > 0 then
        local cards = room:askForCardsChosen(player, room:getPlayerById(to[1]), 1, 1, "he", self.name)
        room:throwCard(cards, self.name, room:getPlayerById(to[1]), player)
      end
    end
  end,
}
Fk:addSkill(sw_chencang)
Fk:loadTranslationTable {
  ["sw_chencang&"] = "陈仓",
  ["#sw_chencang-ask"] = "陈仓：是否发动陈仓，弃置任意角色共计 %arg 张牌",
  ["#sw_nianshou-1"] = "陈仓：选择一名角色，弃置其区域内的一张牌(第 %arg 张，共计 %arg2 张)",
  [":sw_chencang&"] = "结束阶段，你可以弃任意角色区域内的共计6-X张牌(X为你的手牌数)",
}
local sw_chucheng = fk.CreateTriggerSkill {
  name = "sw_chucheng&",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = { fk.DamageCaused },
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash"
        and data.to
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = 0
    room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function(e)
      if (e.data[1] == player or e.data[1] ~= player) and e.data[3] == "recover" then
        n = n + e.data[2]
      end
      return false
    end, Player.HistoryGame)
    data.damage = data.damage + n
  end,
}
Fk:addSkill(sw_chucheng)
Fk:loadTranslationTable {
  ["sw_chucheng&"] = "雏城",
  [":sw_chucheng&"] = "锁定技，当你使用【杀】造成伤害时，此伤害额外+X(X为本局游戏所有角色的回复值)",
}

local sw_xuzhou = fk.CreateTriggerSkill {
  name = "sw_xuzhou&",
  anim_type = "control",
  events = { fk.EventPhaseChanging },
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
        data.to == Player.Finish and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local discard = room:askForDiscard(player, 1, 2, false, self.name, true, ".|.|.|hand", "#sw_xuzhou-ask")
    if #discard > 0 then
      self.cost_data = discard
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(#self.cost_data)
  end
}
local sw_xuzhou_maxcards = fk.CreateMaxCardsSkill {
  name = "#sw_xuzhou_maxcards",
  correct_func = function(self, player)
    if player:hasSkill("sw_xuzhou&") then
      return 3
    end
    return 0
  end
}
sw_xuzhou:addRelatedSkill(sw_xuzhou_maxcards)
Fk:addSkill(sw_xuzhou)

Fk:loadTranslationTable {
  ["sw_xuzhou&"] = "徐州",
  ["#sw_xuzhou-ask"] = "徐州：你可以重铸至多两张牌",
  [":sw_xuzhou&"] = "你的初始手牌和手牌上限+3；结束阶段，你可以重铸至多两张牌",
}
local sw_putong = fk.CreateTriggerSkill {
  name = "sw_putong&",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = { fk.RoundStart },
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    player.room:handleAddLoseSkills(player, "m_feiyang|m_bahu", nil, false)
  end,
}
Fk:addSkill(sw_putong)
Fk:loadTranslationTable {
  ["sw_putong&"] = "荒主",
  [":sw_putong&"] = "你视为拥有飞扬，跋扈",
}
local sw_shameng = fk.CreateTriggerSkill {
  name = "sw_shameng&",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = { fk.DamageInflicted, fk.RoundStart },
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.DamageInflicted then
        return target == player and data.from and player.role == data.from.role and
            player:getMark("@sw_shameng") > 0
      else
        return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      player.room:removePlayerMark(player, "@sw_shameng", 1)
      data.damage = 0
    else
      player.room:addPlayerMark(player, "@sw_shameng", 3)
    end
  end
}
Fk:addSkill(sw_shameng)
Fk:loadTranslationTable {
  ["sw_shameng&"] = "歃血",
  ["@sw_shameng"] = "歃血",
  [":sw_shameng&"] = "锁定技，每局游戏限三次，当你受到来自联军的伤害时(包含自己)，防止之",
}
local sw_bingjin = fk.CreateTriggerSkill {
  name = "sw_bingjin&",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = { fk.TurnEnd },
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player == target and player:hasSkill(self) and player.room:getTag("RoundCount") > 0
  end,
  on_use = function(self, event, target, player, data)
    if player.room:getTag("RoundCount") > 3 then
      player.room:notifySkillInvoked(player, "sw_bingjin&", "offensive")
      player.room:loseHp(player, 1)
    elseif player.room:getTag("RoundCount") == 9 then
      player.room:notifySkillInvoked(player, "sw_bingjin&", "offensive")
      player.room:killPlayer({ who = player.id })
    end
  end
}
Fk:addSkill(sw_bingjin)
Fk:loadTranslationTable {
  ["sw_bingjin&"] = "兵尽",
  [":sw_bingjin&"] = "锁定技，游戏轮次大于3后，结束阶段，你失去一点体力，游戏伦次为7时，结束阶段，你死亡",
}
local sw_liangjue = fk.CreateTriggerSkill {
  name = "sw_liangjue&",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  mute = true,
  events = { fk.DrawNCards, fk.Deathed },
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.DrawNCards then
        return player == target and player.room:getTag("RoundCount") > 4
      else
        return data.damage and data.damage.from == player and player.room:getTag("RoundCount") > 3
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.DrawNCards then
      player.room:notifySkillInvoked(player, "sw_liangjue&", "offensive")
      data.n = data.n - 1
    else
      player.room:gameOver(player.role)
    end
  end
}
Fk:addSkill(sw_liangjue)
Fk:loadTranslationTable {
  ["sw_liangjue&"] = "粮绝",
  [":sw_liangjue&"] = "锁定技，游戏轮次大于4后，摸牌阶段，你少摸一张牌",
}
local sw_yongan = fk.CreateTriggerSkill {
  name = "sw_yongan&",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = { fk.RoundStart },
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    player.room:handleAddLoseSkills(player, "sw_yibing&", nil, false)
  end,
}
Fk:addSkill(sw_yongan)
Fk:loadTranslationTable {
  ["sw_yongan&"] = "永安",
  [":sw_yongan&"] = "你视为拥有疫病",
}
local sw_yibing = fk.CreateTriggerSkill {
  name = "sw_yibing&",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = { fk.DrawNCards, fk.HpLost },
  can_trigger = function(self, event, target, player, data)
    if event == fk.DrawNCards then
      return player:hasSkill(self) and player == target
    else
      return player:hasSkill(self) and player == target and player.role == "lord"
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player.room:notifySkillInvoked(player, "sw_yibing&", "offensive")
    if event == fk.DrawNCards then
      if player.role == "lord" then
        data.n = data.n - 1
      end
      player.room:loseHp(player, 1)
    else
      local ids = room:getCardsFromPileByRule(".", 2)
      if #ids > 0 then
        room:moveCards({
          ids = ids,
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonJustMove,
          proposer = player.id,
          skillName = self.name,
        })
      end
      local pl = 0
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if not p:hasSkill("sw_yibing&") and pl < 2 then
          local to = room:askForChoosePlayers(player, table.map(player.room.alive_players, function(tar)
            return not tar:hasSkill("sw_yibing&") and tar.id
          end), 1, 1, "#sw_yibing", self.name, true)
          if #to > 0 then
            room:handleAddLoseSkills(room:getPlayerById(to[1]), "sw_yibing&", nil, false)
            pl = pl + 1
            break
          end
        end
      end
    end
  end
}
Fk:addSkill(sw_yibing)
Fk:loadTranslationTable {
  ["sw_yibing&"] = "疫病",
  ["#sw_yibing"] = "疫病：选择一名联军，令其获得疫病",
  [":sw_yibing&"] = "锁定技，摸牌阶段，你少摸一张牌并失去一点体力；当你失去体力后，你随机获得牌堆中的两张牌，并令一名角色获得此技能，其不受摸牌减少和失去体力获得牌的效果影响",
}

local ty_1v2_rule = fk.CreateTriggerSkill {
  name = "#ty_1v2_rule",
  priority = 0.001,
  refresh_events = { fk.GameStart, fk.Deathed, fk.DrawInitialCards },
  can_refresh = function(self, event, target, player, data)
    if event == fk.DrawInitialCards then
      return target == player
    else
      return event == fk.GameStart or (target == player and player.rest == 0)
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local skill = player:getMark("chengzhu")
    if event == fk.GameStart then
      if player.role == "lord" then
        room:handleAddLoseSkills(player, skill, nil, false)
        room:setPlayerMark(player, "chengzhu", 0)
        if skill == "sw_yongan&" then
          room:handleAddLoseSkills(player, "sw_yibing&", nil, false)
        else
          room:handleAddLoseSkills(player, "sw_liangjue&", nil, false)
        end
        if skill == "sw_hulao&" then
          room:handleAddLoseSkills(player, "pf_wushuang|mashu", nil, false)
        elseif skill == "sw_yingchuan&" then
          room:handleAddLoseSkills(player, "mobile__god_huishi", nil, false)
        end
        player.maxHp = player.maxHp + 1
        player.hp = player.hp + 1
        room:broadcastProperty(player, "maxHp")
        room:broadcastProperty(player, "hp")
        room:setTag("SkipNormalDeathProcess", true)
      elseif player.role == "rebel" then
        room:handleAddLoseSkills(player, "sw_shameng&|sw_bingjin&", nil, false)
      end
    elseif event == fk.Deathed then
      for _, p in ipairs(room.alive_players) do
        if p.role == "rebel" then
          local choices = { "ty_1v2_draw2", "Cancel" }
          if p:isWounded() then
            table.insert(choices, 2, "ty_1v2_heal")
          end
          local choice = room:askForChoice(p, choices, self.name)
          if choice == "ty_1v2_draw2" then
            p:drawCards(2, self.name)
          else
            room:recover { who = p, num = 1, skillName = self.name }
          end
        end
      end
    else
      if player.seat == 1 then
        data.num = data.num + 1
        if skill == "sw_xuzhou&" then
          data.num = data.num + 2
        end
      end
    end
  end,
}

Fk:addSkill(ty_1v2_rule)
local tenyear_1v2 = fk.CreateGameMode {
  name = "tenyear_1v2",
  minPlayer = 3,
  maxPlayer = 3,
  rule = ty_1v2_rule,
  logic = m_1v2_getLogic,
  surrender_func = function(self, playedTime)
    local surrenderJudge = { { text = "time limitation: 0.08 min", passed = playedTime >= 5 } }
    if Self.role ~= "lord" then
      table.insert(
        surrenderJudge,
        {
          text = "1v2: left you alive",
          passed = #table.filter(Fk:currentRoom().players,
            function(p) return p.rest > 0 or not p.dead end) == 2
        }
      )
    end

    return surrenderJudge
  end,
}

Fk:loadTranslationTable {
  ["tenyear_1v2"] = "兵临城下",
  ["#ty_1v2_rule"] = "挑选遗产",
  ["ty_1v2_draw2"] = "爆他金币，摸俩牌",
  ["ty_1v2_heal"] = "吸他血，回一点体力",

  ["time limitation: 0.08 min"] = "游戏时长达到5秒钟",
  ["1v2: left you alive"] = "仅剩你和地主存活",

  [":tenyear_1v2"] = tenyear_1v2_c,
}

return tenyear_1v2
